import React from 'react';
import { observer } from 'mobx-react';
import { WeaDialog, WeaLocaleProvider } from 'ecCom';
import { WeaRightMenu, WeaNewScroll } from 'ecCom';
import { Button, Modal } from 'antd';
import ConditionStore from '../../stores/dialog/ConditionDialogStore';
import ConditionSet from './ConditionSet';
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class ConditionsettingDialog extends React.Component {

    // 右键菜单
    getRightMenu() {
        let btns = new Array();
        btns.push({ key: "save", icon: <i className='icon-coms-Preservation' />, content: getLabel(86, '保存', 'label') });
        btns.push({ key: "clean", icon: <i className='icon-coms-go-back' />, content: getLabel(15504, "清空") });
        btns.push({ key: "toback", icon: <i className='icon-coms-Revoke' />, content: getLabel(1290, '返回') });
        return btns;
    }

    //右键菜单事件绑定
    onRightMenuClick = (key) => {
        const { store } = this.props;
        const { conditionDialogStore } = store;
        if (key == "save") {
            conditionDialogStore.onSave();
        } else if (key == "clean") {
            conditionDialogStore.deleteCondition();
        } else if (key == "checkSQL") {
            conditionDialogStore.checkSQL(this.toShowErrorSql.bind(this));
        } else if (key == "toback") {
            conditionDialogStore.onCancel();
        }
    }

    render() {
        const { store } = this.props;
        const { conditionDialogStore } = store;
        const { visable } = conditionDialogStore;
        const buttons = new Array();
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@su5vti@save`} type="primary" onClick={() => this.onRightMenuClick('save')} >{getLabel(86, '保存')}</Button>);
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@jvtomm@clean`} onClick={() => this.onRightMenuClick('clean')}>{getLabel(15504, "清空")}</Button>);
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@j8ngc3@$goback`} onClick={() => this.onRightMenuClick('toback')}>{getLabel(1290, '返回')}</Button>);
        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@03rewm`}
                className='cube-dialog cube-page-extend-dialog'
                buttons={buttons}
                title={getLabel(384164, "条件设置")}
                iconBgcolor="#96358a"
                icon='icon-coms-ModelingEngine'
                visible={visable}
                style={{ width: 1200, height: 616 * 0.9 }}
                onCancel={() => this.onRightMenuClick('toback')}
            >
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@g9dcgg`} datas={this.getRightMenu()} onClick={this.onRightMenuClick.bind(this)} height={616 * 0.9} >
                    <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@ks4o6v`} height={616 * 0.9}>
                        <ConditionSet ecId={`${this && this.props && this.props.ecId || ''}_ConditionSet@01qkrj`} store={conditionDialogStore} />
                    </WeaNewScroll>
                </WeaRightMenu>
            </WeaDialog >
        )
    }
}
